#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <PowerupsX>

#define PREFIX "{olive}PowerupsX {default}>{green} "

new AbilityBarrel;

new String:CTSkins[4][64] = { "models/player/ct_gign.mdl",
"models/player/ct_gsg9.mdl",
"models/player/ct_sas.mdl",
"models/player/ct_urban.mdl"};

new String:TSkins[4][64] = { "models/player/t_arctic.mdl",
"models/player/t_guerilla.mdl",
"models/player/t_leet.mdl",
"models/player/t_phoenix.mdl"};


public Plugin:myinfo= 
{
	name="PowerupsXL Barrel",
	author="Skydive",
	description="Powerups X Barrel Ability",
	version="1.0",
	url=""
};

public OnMapStart()
{
	PrecacheModel("models/props_c17/oildrum001.mdl",true);
}

public OnPluginStart()
{
	NativeIncStart();
	
	AbilityBarrel = PX_RegisterAbility("AbilityBarrel");
	PX_SetAbilityName(AbilityBarrel,"Disguise");
	PX_SetAbilityDescription(AbilityBarrel,"Disguises You. Level 2: Barrel Disguise. Max. 5: Random Barrel Skin.");
	PX_SetAbilityUsage(AbilityBarrel,"Disguises you as a Barrel. Try to blend in!");
	PX_SetAbilityMaxLevel(AbilityBarrel,5);
	
	HookEvent("player_spawn",Event_PlayerSpawn);
}

public Action:Event_PlayerSpawn(Handle:event, const String:name[],bool:dontBroadcast)
{
	new userid = GetClientOfUserId(GetEventInt(event,"userid"));
	new Level = PX_GetLevel(userid, PX_GetAbility(userid));
	
	if(PX_GetAbility(userid) == AbilityBarrel)
	{
		if(Level < 2)
		{
			DisguiseClient(userid, true);
		}
		else if(Level >= 2)
		{
			SetEntityModel(userid,"models/props_c17/oildrum001.mdl");
			new i = Math_GetRandomInt(1,6);
			SetEntProp(userid, Prop_Send, "m_nSkin", i);
		}
		else if(Level >= 5)
		{
			//
		}
	}
}

public PXF_OnAbilityGiven(Client, Ability)
{
	new Level = PX_GetLevel(Client, Ability);
	if(Ability == AbilityBarrel)
	{
		if(Level < 2)
		{
			DisguiseClient(Client, true);
		}
		else if(Level >= 2)
		{
			SetEntityModel(Client,"models/props_c17/oildrum001.mdl");
			new i = Math_GetRandomInt(1,6);
			SetEntProp(Client, Prop_Send, "m_nSkin", i);
		}
		else if(Level >= 5)
		{
			
		}
	}
}

public PXF_OnAbilityRemoved(Client, Ability)
{
	if(Ability == AbilityBarrel)
	{
		DisguiseClient(Client, false);
	}
}

DisguiseClient(Client,bool:Active)
{
	if(Active)
	{
		new i = Math_GetRandomInt(0,3);
		if(GetClientTeam(Client) == CS_TEAM_CT)
		{
			SetEntityModel(Client,CTSkins[i]);
		}
		else if(GetClientTeam(Client) == CS_TEAM_T)
		{
			SetEntityModel(Client,TSkins[i]);
		}
	}
	else
	{
		if(GetClientTeam(Client) == CS_TEAM_CT)
		{
			SetEntityModel(Client,"models/player/ct_gign.mdl");
		}
		else if(GetClientTeam(Client) == CS_TEAM_T)
		{
			SetEntityModel(Client,"models/player/t_leet.mdl");
		}
	}
}